home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / MW MPW Binaries 1.1.1a2 / mwcPPC / MWCIncludes / ios < prev    next >
Encoding:
Text File  |  1994-07-18  |  4.1 KB  |  182 lines  |  [TEXT/MMCC]

  1. // ios standard header
  2. #ifndef _IOS_
  3. #define _IOS_
  4. #include <exception>
  5.  
  6. #if __MWERKS__
  7. #pragma options align=mac68k
  8. #endif
  9.  
  10.         // I/O exception macros
  11. #if _CATCH_IO_EXCEPTIONS
  12.  #define _TRY_IO_BEGIN    _TRY_BEGIN
  13.  #define _CATCH_IO_END    _CATCH_ALL \
  14.     setstate(failbit); _RERAISE; _CATCH_END
  15.  #define _CATCH_IO_(x)    _CATCH_ALL \
  16.     (x).setstate(ios::failbit); _RERAISE; _CATCH_END
  17. #else
  18.  #define _TRY_IO_BEGIN    {
  19.  #define _CATCH_IO_END    }
  20.  #define _CATCH_IO_(x)    }
  21. #endif
  22. class ostream; class streambuf;
  23.         // class ios
  24. class ios {
  25. public:
  26.             // class failure
  27.     class failure : public xmsg {
  28.     public:
  29.         failure(const char *_X = 0, const char *_Y = 0,
  30.             const char *_Z = 0)
  31.             : xmsg(_X, _Y, _Z) {};
  32.         virtual ~failure();
  33.     protected:
  34.         virtual void do_raise();
  35.     };
  36.     enum _Fmtflags {skipws = 0x0001, unitbuf = 0x0002,
  37.         uppercase = 0x0004, showbase = 0x0008,
  38.         showpoint = 0x0010, showpos = 0x0020,
  39.         left = 0x0040, right = 0x0080, internal = 0x0100,
  40.         dec = 0x0200, oct = 0x0400, hex = 0x0800,
  41.         scientific = 0x1000, fixed = 0x2000,
  42.         adjustfield = 0x01c0, basefield = 0x0e00,
  43.         floatfield = 0x3000, _Fmtmask = 0x3fff, _Fmtzero = 0};
  44.     enum _Iostate {goodbit = 0x0, eofbit = 0x1,
  45.         failbit = 0x2, badbit = 0x4, _Statmask = 0x7};
  46.     enum _Openmode {in = 0x01, out = 0x02, ate = 0x04,
  47.         app = 0x08, trunc = 0x10, binary = 0x20};
  48.     enum seekdir {beg = 0, cur = 1, end = 2};
  49.     _BITMASK(_Fmtflags, fmtflags);
  50.     _BITMASK(_Iostate, iostate);
  51.     _BITMASK(_Openmode, openmode);
  52.     typedef int io_state, open_mode, seek_dir;
  53.     enum _Uninitialized {_Noinit};
  54.             // class Init
  55.     class Init {
  56.     public:
  57.         Init();
  58.         ~Init();
  59.     private:
  60.         static int _Init_cnt;
  61.         };
  62.             // class _Iosarray
  63.     class _Iosarray {
  64.     public:
  65.         _Iosarray(int _Idx, _Iosarray *_Link = 0)
  66.             : _Next(_Link), _Index(_Idx), _Lo(0), _Vp(0) {}
  67.         _Iosarray *_Next;
  68.         int _Index;
  69.         long _Lo;
  70.         void *_Vp;
  71.         };
  72.     ios(streambuf *_S)
  73.         {init(_S); }
  74.     virtual ~ios();
  75.     operator void *() const
  76.         {return (void *)(!*this ? 0 : this); }
  77.     _Bool operator!() const
  78.         {return ((_State & (failbit|badbit)) != 0); }
  79.     ios& copyfmt(const ios&);
  80.     ostream *tie() const
  81.         {return (_Tiestr); }
  82.     ostream *tie(ostream *);
  83.     streambuf *rdbuf() const
  84.         {return (_Sb); }
  85.     streambuf *rdbuf(streambuf *);
  86.     iostate rdstate() const
  87.         {return (_State); }
  88.     void clear(iostate = goodbit);
  89.     void setstate(iostate _St)
  90.         {clear(_State | _St); }
  91.     _Bool good() const
  92.         {return (_State == goodbit); }
  93.     _Bool eof() const
  94.         {return (_State & eofbit); }
  95.     _Bool fail() const
  96.         {return (_State & (badbit | failbit)); }
  97.     _Bool bad() const
  98.         {return (_State & badbit); }
  99.     iostate exceptions() const
  100.         {return (_Except); }
  101.     void exceptions(iostate);
  102.     fmtflags flags() const
  103.         {return (_Fmtfl); }
  104.     fmtflags flags(fmtflags);
  105.     fmtflags setf(fmtflags);
  106.     fmtflags setf(fmtflags, fmtflags);
  107.     void unsetf(fmtflags);
  108.     int fill() const
  109.         {return (_Fillch); }
  110.     int fill(int);
  111.     int precision() const
  112.         {return (_Prec); }
  113.     int precision(int);
  114.     int width() const
  115.         {return (_Wide); }
  116.     int width(int);
  117.     static int xalloc()
  118.         {return (_Index++); }
  119.     long& iword(int _Idx)
  120.         {return (_Findarr(_Idx)._Lo); }
  121.     void *& pword(int _Idx)
  122.         {return (_Findarr(_Idx)._Vp); }
  123. #if _HAS_ENUM_OVERLOADING
  124.     void clear(io_state _St = 0)
  125.         {clear((iostate)_St); }
  126.     void setstate(io_state _St)
  127.         {setstate((iostate)_St); }
  128.     void exceptions(io_state _St)
  129.         {exceptions(iostate)_St); }
  130. #endif
  131. protected:
  132.     ios()
  133.         {init(0); }
  134.     ios(_Uninitialized)
  135.         {}
  136.     ios(const ios&);
  137.     ios& operator=(const ios&);
  138.     void init(streambuf *);
  139. private:
  140.     streambuf *_Sb;
  141.     ostream *_Tiestr;
  142.     iostate _State, _Except;
  143.     fmtflags _Fmtfl;
  144.     int _Prec, _Wide;
  145.     char _Fillch;
  146.     static int _Index;
  147.     _Iosarray *_Arr;
  148.     _Iosarray& _Findarr(int);
  149.     void _Tidy();
  150.     };
  151.         // manipulators
  152. ios& dec(ios&);
  153. ios& fixed(ios&);
  154. ios& hex(ios&);
  155. ios& internal(ios&);
  156. ios& left(ios&);
  157. ios& noshowbase(ios&);
  158. ios& noshowpoint(ios&);
  159. ios& noshowpos(ios&);
  160. ios& noskipws(ios&);
  161. ios& nouppercase(ios&);
  162. ios& oct(ios&);
  163. ios& right(ios&);
  164. ios& scientific(ios&);
  165. ios& showbase(ios&);
  166. ios& showpoint(ios&);
  167. ios& showpos(ios&);
  168. ios& skipws(ios&);
  169. ios& uppercase(ios&);
  170.  
  171. #if __MWERKS__
  172. #pragma options align=reset
  173. #endif
  174.  
  175. #endif
  176.  
  177. /*
  178.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  179.  * Consult your license regarding permissions and restrictions.
  180.  */
  181.  
  182.